package sdk.org.apache.shiro.G2_使用.C04_登录和退出带多Realm配置;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.titan.core.utils.debug.Timer;

import sdk.org.apache.shiro.utils.ShiroUtils;

public class Main {
    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
            run(timer);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print("执行总用时");
            System.exit(0);
        }
    }

    
    private static void run(Timer timer) throws Exception {
        ShiroUtils.init(
                  new sdk.org.apache.shiro.G2_使用.C04_登录和退出带多Realm配置.realms.MyRealm1()
                , new sdk.org.apache.shiro.G2_使用.C04_登录和退出带多Realm配置.realms.MyRealm2()
                );
        
        Subject currentUser = ShiroUtils.login("zhang", "123", true);
        System.out.println("当前用户"+currentUser.getPrincipal()+"的登录状态："+currentUser.isAuthenticated());
        ShiroUtils.logout();
        
        currentUser = ShiroUtils.login("wang", "123", true);
        System.out.println("当前用户"+currentUser.getPrincipal()+"的登录状态："+currentUser.isAuthenticated());
        ShiroUtils.logout();
    }
}
